package com.hockeo.client.ui.base;

import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.hockeo.client.model.JSData;

/**
 * Base class for all VH combo boxes.
 *
 * @version $Id$
 * @author jjanke
 */
public abstract class VHComboBox extends LayoutContainer
{
  private final ListStore<JSData> d_store;
  private final ComboBox<JSData>  d_combobox;
  private JSData                  d_dataDefault;
  private boolean                 d_fInitialised = false;

  public VHComboBox()
  {
    d_store = new ListStore<JSData>();
    d_combobox = new ComboBox<JSData>();

    d_combobox.setStore( d_store );
    d_combobox.setLazyRender( true );
    d_combobox.setEditable( false );
    d_combobox.setAllowBlank( false );
    d_combobox.setForceSelection( true );
    d_combobox.setTriggerAction( TriggerAction.ALL );

    add( d_combobox );
  }

  /**
   * Indicates whether the underlying data store has been loaded at least once.
   */
  public final boolean isInitialised()
  {
    return d_fInitialised;
  }

  protected final void setInitialised( boolean flag )
  {
    d_fInitialised = flag;
  }

  protected final ListStore<JSData> getStore()
  {
    return d_store;
  }

  public final ComboBox<JSData> getCombobox()
  {
    return d_combobox;
  }

  public final void setDefault( JSData data )
  {
    d_dataDefault = data;
  }

  public final JSData getDefault()
  {
    return d_dataDefault;
  }

  public final void selectDefault()
  {
    d_combobox.setValue( d_dataDefault );
  }
}
